package com.yangcangclub.system.component;


import com.yangcangclub.system.domain.WxEvent;
import com.yangcangclub.commons.exception.ApolloException;
import com.yangcangclub.commons.result.MessageEnum;
import com.yangcangclub.commons.utils.StringUtil;
import com.yangcangclub.system.domain.PushConfig;
import com.yangcangclub.system.domain.Sequence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


@Component
public class SystemComponent {

    @Autowired
    PushConfig pushConfig;
    @Autowired
    Sequence sequence;
    @Autowired
    WxEvent wxEvent;
    /**
     * 查询个人配置list
     */
    public List<Map<String,Integer>> queryUserConflist(int userId){
        return pushConfig.queryConflist(userId);
    }



    /**
     * 当前系列的下一个值
     */
    public int queryNextval(String key){
        if(StringUtil.isEmpty(key)){
            throw new ApolloException(MessageEnum.PARMA_IS_EMPTY);
        }
        return sequence.queryNextval(key);
    }


    /**
     * 当前系列的当前值
     */
    public int queryCurrval(String key){
        if(StringUtil.isEmpty(key)){
            throw new ApolloException(MessageEnum.PARMA_IS_EMPTY);
        }
        return sequence.queryCurrval(key);
    }

    /**
     * 保存微信事件
     * @return
     */
    public int insertWxEvent(String toUserName,String fromUserName,String createTime,String msgType,String event,String eventKey,String ticket) {
        return wxEvent.insertWxEvent(toUserName,fromUserName,createTime,msgType,event,eventKey,ticket);
    }
}
